<?php

/**
 * 
 * @author yuxun
 *
 */
class RechargeUrlService extends Service{
	
	public static function indexHeader(){
		return array(
				'id'         => array('text' => 'ID', 'rule' => 'int'),				
				'channel'    => array('text' => '渠道'),
				'packet'     => array('text' => '包号'),
				'money_18'      => array('text' => '充值URL(18元)'),
				'money_6'      => array('text' => '充值URL(16元)'),
				'money_30'      => array('text' => '充值URL(30元)'),
				'money_68'      => array('text' => '充值URL(68元)'),
				'money_128'      => array('text' => '充值URL(128元)'),
				'money_198'      => array('text' => '充值URL(198元)'),
				'money_328'      => array('text' => '充值URL(328元)'),
				'money_648'      => array('text' => '充值URL(648元)'),
				'create_time'     => array('text' => '添加时间'),
				'action'     => array('text' => '操作')
		);
	}
	
	public static function indexData($params){
		$modRechargeUrl = new ModRechargeUrl();
		$result = $modRechargeUrl->page($params);
		$length = count($result['data']);
		foreach($result['data'] as &$v){
			$type = 1;
			if($k == 0 && $length == 1){  //当前页只剩下一条数据时，删除之后需显示上一页的数据
				$type = 2;
			}
			
			
			$v['create_time'] = date('Y-m-d H:i:s', $v['create_time']);
			$v['action']  .= ' <a href="'.PubFunc::buildBackUrl('/oss/?r=rechargeUrl/edit').'&id='.$v['id'].'">编辑</a>';
			$v['action']  .= ' <a href="'.PubFunc::buildBackUrl('/oss/?r=rechargeUrl/delete',$type).'&id='.$v['id'].'" onclick="del()" confirm="是否要删除该条服信息?">删除</a>';
		}
		unset($v);
		return $result;
	}
	
	public static function doAdd($params){
		$user = AccAuth::me();
	
		$modRechargeUrl = new ModRechargeUrl();
		$modRechargeUrl->game = $params['g'];
		$modRechargeUrl->channel   = $params['channel'];
		$modRechargeUrl->packet   = $params['packet'];
		$modRechargeUrl->money_18  = $params['money_18'];
		$modRechargeUrl->money_6  = $params['money_6'];	
		$modRechargeUrl->money_30  = $params['money_30'];
		$modRechargeUrl->money_68  = $params['money_68'];
		$modRechargeUrl->money_128  = $params['money_128'];
		$modRechargeUrl->money_198  = $params['money_198'];
		$modRechargeUrl->money_328  = $params['money_328'];
		$modRechargeUrl->money_648  = $params['money_648'];
			
		$modRechargeUrl->create_user   = $user['UserID'];
		$modRechargeUrl->create_time   = time();
		$modRechargeUrl->update_user   = $user['UserID'];
		$modRechargeUrl->update_time   = time();
		
		$result = $modRechargeUrl->save();
		return array('state' => true, 'msg' => '成功增加');
	}
	
	public static function get($id){
		$modRechargeUrl = new ModRechargeUrl();
		$obj = $modRechargeUrl->findByPk($id);
	
		if($obj){
			$info = $obj->getAttributes();
			return $info;
		}else{
			return false;
		}
	}
	
	public static function doEdit($id, $params){
		if(empty($id)) return array('state' => false, 'msg' => '信息不存在');

		$user = AccAuth::me();
		$modRechargeUrl = new ModRechargeUrl();
		$update = array();
	
		$update['channel'] = $params['channel'];
		$update['packet'] = $params['packet'];
		$update['money_18'] = $params['money_18'];
		$update['money_6'] = $params['money_6'];
		$update['money_30'] = $params['money_30'];
		$update['money_68'] = $params['money_68'];
		$update['money_128'] = $params['money_128'];
		$update['money_198'] = $params['money_198'];
		$update['money_328'] = $params['money_328'];
		$update['money_648'] = $params['money_648'];
		
		$update['update_user']  = $user['UserID'];
		$update['update_time']  = time();
		
		$result = $modRechargeUrl->updateByPk($id, $update);

		return true;
	}
	
	public static function delete($id){
		if(empty($id)) return false;		
		$modRechargeUrl = new ModRechargeUrl();
		$modRechargeUrl->deleteByPk($id);
		return array('state' => true, 'msg' => '成功删除');
	}
	
	
	/*
	 * 去重
	 */
	public static function repeat($id = 0, $field1, $val1,$field2, $val2,$g){
		$modRechargeUrl = new ModRechargeUrl();
		$conut = $modRechargeUrl->repeat($id, $field1, $val1,$field2, $val2,$g);
		return $conut;
	}
	
	


}